package com.qf.flash.mvp.presenter;

import com.qf.flash.http.HttpManager;
import com.qf.flash.model.RegionBean;
import com.qf.flash.mvp.contract.RegionContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

/**
 * 创建日期：2020/3/9 on 10:28
 * 描述:
 * 作者:戴旭东
 */
public class RegionPresenter extends BasePresenter<RegionContract.View> implements RegionContract.Presenter {

    @Override
    public void getRegionList() {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .REGION_LIST()
                .compose(RxUtils.<List<RegionBean>>handleResult())
                .compose(RxUtils.<List<RegionBean>>io_main())
                .subscribeWith(new BaseSubscriber<List<RegionBean>>(mRootView) {
                    @Override
                    public void onSuccess(List<RegionBean> scriptRoomBeans) {
                        mRootView.setRegionListData(scriptRoomBeans);
                    }
                })
        );
    }

    @Override
    public void getSubCity(String pid) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SUB_CITY(pid)
                .compose(RxUtils.<List<RegionBean>>handleResult())
                .compose(RxUtils.<List<RegionBean>>io_main())
                .subscribeWith(new BaseSubscriber<List<RegionBean>>(mRootView) {
                    @Override
                    public void onSuccess(List<RegionBean> scriptRoomBeans) {
                        mRootView.setRegionListData(scriptRoomBeans);
                    }
                })
        );
    }
}
